<template>
  <div class="detail">
    <van-nav-bar
      :title="$t('order.detailOrder')"
      left-arrow
      @click-left="onClickLeft()"
    />
    <div class="detail-body">
      <div class="body-top detail-flex">
        <span class="top-text"> {{ t("order.cardTypeName") }}</span>
        <span
          :class="
            data.status == 0 ? '' : data.status == 1 ? 'success' : 'error'
          "
          >{{ cardType(data.status) }}</span
        >
      </div>
      <van-divider />
      <div class="detail-body-a">
        <img :src="data.cardIconUrl" alt="" class="detail-img" />
        <span class="text">{{ type(data.recycleType) }}</span>
      </div>
      <div class="detail-body-card detail-flex">
        <span class="left-text">{{ t("order.cardValue") }}</span>
        <span class="right-text">{{ data.cardMoney }}</span>
      </div>
      <div class="detail-body-card detail-flex">
        <span class="left-text">{{ t("order.cardType") }}</span>
        <span class="right-text"> {{ type(data.recycleType) }}</span>
      </div>
      <div class="detail-body-card detail-flex">
        <span class="left-text">{{ t("order.cardCode") }}</span>
        <span class="right-text"> {{ data.cardCode }}</span>
      </div>
      <div class="detail-body-card" @click="onShow(data.cardImageUrl)">
        <span class="left-text">{{ t("order.cardImg") }}</span>
        <span class="right-view-img" v-if="data.cardImageUrl">{{
          t("order.viewImg")
        }}</span>
        <div class="right-img" @click="onShow(data.cardImageUrl)">
          <img
            :src="data.cardImageUrl"
            alt=""
            v-if="data.cardImageUrl"
            class="card-img"
          />
          <img src="@/assets/images/none.png" v-else alt="" class="none-img" />
        </div>
      </div>
      <div class="detail-body-card" @click="onShow(data.image)">
        <span class="left-text">{{ t("two.voucher") }}</span>
        <span class="right-view-img" v-if="data.image">{{
          t("order.viewImg")
        }}</span>
        <div class="right-img" @click="onShow(data.image)">
          <img :src="data.image" alt="" v-if="data.image" class="card-img" />
          <img src="@/assets/images/none.png" v-else alt="" class="none-img" />
        </div>
      </div>
      <div class="detail-body-card detail-flex">
        <span class="left-text">{{ t("order.totalPrice") }}</span>
        <span class="right-text-a">
          {{ t("moneyIcon") }}{{ data.totalPrice }}</span
        >
      </div>
      <div class="detail-body-card detail-flex">
        <span class="left-text">{{ t("two.reason") }}</span>
        <span class="right-text"> {{ data.remark }}</span>
      </div>
      <div class="detail-body-card detail-flex">
        <span class="left-text">{{ t("order.orderScore") }}</span>
        <span class="right-text"> {{ data.integral }}</span>
      </div>
      <div class="detail-body-card detail-flex">
        <span class="left-text">{{ t("order.orderTime") }}</span>
        <span class="right-text"> {{ data.addTime }}</span>
      </div>
      <div class="detail-body-card detail-flex" v-if="data.remark">
        <span class="left-text">{{ t("order.reason") }}</span>
        <span class="right-text"> {{ data.remark }}</span>
      </div>
      <div class="detail-body-card detail-flex" v-if="data.image">
        <span class="left-text">{{ t("order.voucher") }}</span>
        <div class="right-img" @click="onShow(data.image)">
          <img :src="data.image" alt="" v-if="data.image" class="card-img" />
        </div>
      </div>

      <div class="detail-body-card detail-flex">
        <span class="left-text">{{ t("order.orderNum") }}</span>
        <span class="right-text"> {{ data.orderNo }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from "@vue/reactivity";
import { ImagePreview } from "vant";
import { useI18n } from "vue-i18n";
import { useRouter, useRoute } from "vue-router";
import { getSingleOrder } from "@/api/user";
import { onMounted } from "vue";
const router = useRouter();
const route = useRoute();
const { t } = useI18n();
let data = reactive({
  status: 0,
  cardCode: "", //卡片code
  integral: "", //积分
  orderNo: "", //订单编号
  cardMoney: "", //卡片面额
  totalPrice: "", //订单总价
  addTime: "", //订单时间
  recycleType: "", //卡片类型
  cardImageUrl: "", //卖卡图片
  cardIconUrl: "", //卡片类型
});
function onShow(img) {
  if (!img.length) return;
  ImagePreview([img]);
}
onMounted(async () => {
  console.log(route.query);
  let res = await getSingleOrder({ id: route.query.id }).catch((err) => {
    console.log(err);
  });
  Object.assign(data, res.data);
  console.log(data);
});
function cardType(type) {
  switch (Number(type)) {
    case 0:
      return t("order.orderDoing");
      break;
    case 1:
      return t("order.orderSuccess");
      break;
    case 2:
      return t("order.orderFail");
      break;
  }
}
function type(val) {
  if (val == 1) {
    return t("order.typeImg");
  } else if (val == 2) {
    return t("order.typePass");
  } else {
    return val;
  }
}
function onClickLeft() {
  history.back();
}
</script>

<style lang="less" scoped>
.detail {
  background: #e9e9e9;
  width: 100%;
  height: 100%;
  .top-text {
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #999999;
    line-height: 16px;
  }
  .status-text {
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    line-height: 14px;
    color: #333333;
  }
  &-flex {
    display: flex;
    justify-content: space-between;
  }
  .success {
    color: #17c600;
  }
  .error {
    color: #e50000;
  }
  &-body {
    margin-top: 3px;
    border-radius: 10px;
    height: calc(100% - 69px);
    background: white;
    overflow: auto;
    padding: 10px 20px;
    &-a {
      position: relative;
      .text {
        position: absolute;
        top: 8px;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #333333;
        line-height: 16px;
        margin-left: 12px;
      }
    }
    &-card {
      padding: 10px 14px;
      background: #fafafa;
      border-radius: 10px;
      margin-bottom: 15px;
      .left-text {
        font-size: 15px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #333333;
        line-height: 15px;
        min-width: 65px;
      }
      .right-text {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #525252;
        line-height: 14px;
      }
      .right-text-a {
        font-size: 19px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #ed008c;
        line-height: 19px;
      }
      .right-img {
        width: 100%;
        min-height: 108px;
        border-radius: 10px;
        background: #fffdff;
        margin-top: 10px;
        text-align: center;
      }
      .none-img {
        width: 88px;
        height: 69px;
        margin-top: 20px;
      }
      .card-img {
        width: 100%;
        border-radius: 10px;
      }
    }
  }

  &-img {
    width: 34px;
    height: 34px;
  }
  .right-view-img {
    float: right;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #525252;
    line-height: 14px;
  }
}
</style>
